package cn.hinglo.gameclaw.client.action;

import cn.hinglo.gameclaw.admin.service.FeedBackService;
import cn.hinglo.gameclaw.data.controller.BaseController;
import cn.hinglo.gameclaw.data.entity.Result;
import cn.hinglo.gameclaw.user.bean.FeedBack;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @createTime: 2018/1/11
 * @author: HingLo
 * @description: 反馈信息处理
 */
@RestController
@RequestMapping("client/fc/")
public class FeedBackClientAction extends BaseController {


    private final FeedBackService feedBackService;

    @Autowired
    public FeedBackClientAction(FeedBackService feedBackService) {
        this.feedBackService = feedBackService;
    }


    /**
     * 添加反馈信息
     *
     * @param feedBack      反馈信息
     * @param bindingResult 错误结果信息绑定对象
     * @return 操作结果, 返回是否能否返回
     */
    @PostMapping("add")
    public Result addFeedBack(@Valid FeedBack feedBack, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return error(bindingResult.getFieldError().getDefaultMessage());
        }
        String userId = getUserId(request);
        feedBack.setUserId(userId);
        return feedBackService.addFeedBackService(feedBack);
    }

}
